home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / flonum.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  4.3 KB  |  171 lines

  1. #ifndef FLONUM_H
  2. #define FLONUM_H
  3.  
  4. /* Defs and macros for floating point code.  This stuff is heavily based
  5.    on Scott McCauley's code, except that this version works :-} */
  6.  
  7.  
  8. /* These definitions work for machines where an SF value is
  9.    returned in the same register as an int.  */
  10.  
  11. #ifndef SFVALUE  
  12. #define SFVALUE int
  13. #endif
  14.  
  15. #ifndef INTIFY
  16. #define INTIFY(FLOATVAL)  (intify.f = (FLOATVAL), intify.i)
  17. #endif
  18.  
  19. /* quasi-IEEE floating point number definitions */
  20.  
  21. struct bitfloat {
  22.     unsigned long sign : 1;
  23.     unsigned long exp  : 8;
  24.     unsigned long mant : 23;
  25. };
  26.  
  27. struct bitdouble {
  28.     unsigned long sign  : 1;
  29.     unsigned long exp   : 11;
  30.     unsigned long mant1 : 20;
  31.     unsigned long mant2;
  32. };
  33.  
  34. union double_di {
  35.         double d;
  36.     long   i[2];
  37. };
  38.  
  39. union flt_or_int {
  40.         long  i;
  41.         float f;
  42. };
  43.  
  44. #ifdef WORDS_BIG_ENDIAN
  45. #  define HIGH 0
  46. #  define LOW 1
  47. #else
  48. #  define HIGH 1
  49. #  define LOW 0
  50. #endif
  51.  
  52. /* start of symbolic asm definitions */
  53.  
  54. /* you may have to change the g's to d's if you start getting
  55.    illegal operands from as */
  56.  
  57. #define MUL(a, b) \
  58.     asm volatile ("mulu    %2,%0"     : "=d" (b)    : "0" (b) , "g" (a))
  59.  
  60. #define DIV(a, b) \
  61.     asm volatile ("divu %2,%0"     : "=d" (b)    : "0" (b) , "g" (a))
  62.  
  63. #define SWAP(a)      \
  64.     asm volatile ("swap    %0"     : "=r" (a)     : "0" (a))
  65.  
  66. #define ASL2(r1, r2) { \
  67.     asm volatile ("asll  #1,%0"    : "=d" (r2)     : "0" (r2));    \
  68.     asm volatile ("roxll #1,%0" : "=d" (r1)    : "0" (r1));    \
  69.     }
  70.  
  71. #define ASL3(r1, r2, r3) { \
  72.     asm volatile ("asll  #1,%0" : "=d" (r3)     : "0" (r3));    \
  73.     asm volatile ("roxll #1,%0" : "=d" (r2)     : "0" (r2));    \
  74.     asm volatile ("roxll #1,%0" : "=d" (r1)     : "0" (r1));     \
  75.     }
  76.  
  77. #define ASR2(r1, r2) {    \
  78.     asm volatile ("asrl  #1,%0" : "=d" (r1)     : "0" (r1));    \
  79.     asm volatile ("roxrl #1,%0" : "=d" (r2)     : "0" (r2));    \
  80.     }
  81.  
  82. #define ASR3(r1, r2, r3) { \
  83.     asm volatile ("asrl  #1,%0" : "=d" (r1)     : "0" (r1));    \
  84.     asm volatile ("roxrl #1,%0" : "=d" (r2)     : "0" (r2));    \
  85.     asm volatile ("roxrl #1,%0" : "=d" (r3)     : "0" (r3));    \
  86.     }
  87.  
  88. #define ASR4(r1, r2, r3, r4) { \
  89.     asm volatile ("asrl  #1,%0" : "=d" (r1)     : "0" (r1));    \
  90.     asm volatile ("roxrl #1,%0" : "=d" (r2)     : "0" (r2));    \
  91.     asm volatile ("roxrl #1,%0" : "=d" (r3)    : "0" (r3));    \
  92.     asm volatile ("roxrl #1,%0" : "=d" (r4)     : "0" (r4));    \
  93.     }
  94.  
  95. #define ADD2(r1, r2, r3, r4) { \
  96.     asm volatile ("addl  %2,%0"    : "=g" (r4)     : "0" (r4) , "g" (r2));    \
  97.     asm volatile ("addxl %2,%0"    : "=g" (r3)    : "0" (r3) , "g" (r1));    \
  98.     }
  99.  
  100. /* y <- y - x  */
  101. #define SUB3(x1, x2, x3, y1, y2, y3) { \
  102.     asm volatile ("subl  %2,%0"    : "=g" (y3)    : "0" (y3) , "d" (x3));    \
  103.     asm volatile ("subxl %2,%0"    : "=g" (y2)     : "0" (y2) , "d" (x2)); \
  104.     asm volatile ("subxl %2,%0"    : "=g" (y1)     : "0" (y1) , "d" (x1));    \
  105.     }
  106.  
  107. /* sub4 here is rather complex, as the compiler is overwhelmed by me wanting
  108.    to have 8 data registers allocated for mantissa accumulators.  Help it out
  109.    by declaring a temp that it can move stuff in and out of.  */
  110. #define SUB4(x1, x2, x3, x4, y1, y2, y3, y4) { \
  111.     register long temp = y4;                          \
  112.     asm volatile ("subl  %2,%0"    : "=d" (temp)    : "0" (temp) , "d" (x4)); \
  113.     y4 = temp; temp = y3;                           \
  114.     asm volatile ("subxl %2,%0"    : "=d" (temp)    : "0" (temp) , "d" (x3)); \
  115.     y3 = temp; temp = y2;                          \
  116.     asm volatile ("subxl %2,%0"    : "=d" (temp)    : "0" (temp) , "d" (x2)); \
  117.     y2 = temp; temp = y1;                          \
  118.     asm volatile ("subxl %2,%0"    : "=d" (temp)    : "0" (temp) , "d" (x1)); \
  119.     y1 = temp;                                  \
  120.     }
  121.  
  122. #define NEG(r1, r2) { \
  123.     asm volatile ("negl  %0"    : "=d" (r2)    : "0" (r2));    \
  124.     asm volatile ("negxl %0"     : "=d" (r1)     : "0" (r1));    \
  125.     } 
  126.  
  127. /* switches for which routines to compile.  All the single-float and
  128. long-int arithmetic routines are turned off here, as they were all
  129. done in assembly language last year.  */
  130.  
  131. #if 0
  132. #define L_umulsi3
  133. #define L_mulsi3
  134. #define L_udivsi3
  135. #define L_divsi3
  136. #define L_umodsi3
  137. #define L_modsi3
  138. #define L_lshrsi3
  139. #define L_lshlsi3
  140. #define L_ashrsi3
  141. #define L_ashlsi3
  142. #endif
  143.  
  144. #if 0
  145. #define L_divdf3
  146. #define L_muldf3
  147. #define L_negdf2
  148. #define L_adddf3
  149. #define L_subdf3
  150. #define L_cmpdf2
  151. #define L_fixunsdfsi
  152. #define L_floatsidf
  153. #define L_truncdfsf2
  154. #define L_extendsfdf2
  155. #endif
  156.  
  157. #if 0
  158. #define L_fixunsdfdi
  159. #define L_fixdfdi
  160. #define L_floatdidf
  161.  
  162. #define L_addsf3
  163. #define L_negsf2
  164. #define L_subsf3
  165. #define L_cmpsf2
  166. #define L_mulsf3
  167. #define L_divsf3
  168. #endif
  169.  
  170. #endif /* FLONUM_H */
  171.